home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bccapp.zip / ACCESS.H < prev    next >
C/C++ Source or Header  |  1991-09-15  |  3KB  |  113 lines

  1. /*
  2.  *
  3.  * Record manipulation.  Provides Saving/Restoring of C++ structures.
  4.  * This is a superclass that provides structured file I/O for both
  5.  * the DATABASE and INDEX classes.
  6.  *
  7.  * (C) 1990 Vision Software
  8.  *
  9.  * $Id: access.h 1.2001 91/04/25 15:06:47 pcalvin release $
  10.  *
  11.  * Comments:
  12.  *
  13.  * In general, the PUBLIC does not need to use this class directly.  DATABASE
  14.  * provides a much cleaner interface for most applications.  This class may
  15.  * be used if the application wants to bypass indexing.
  16.  *
  17.  * Bugs:
  18.  *
  19.  * Right now, no caching takes place.  This is not technically a bug,
  20.  * but caching would improve the performance of all disk access by
  21.  * a large degree.  It would not be difficult to implement a LRU algorithm
  22.  * for record access.
  23.  *
  24.  */
  25. #if (!defined(__ACCESS__))
  26. #define __ACCESS__
  27.  
  28. /*
  29.  * Record manipulation(General usage)
  30.  */
  31. typedef UINT REC;
  32. STATIC CONST REC recNil = 0;
  33. STATIC CONST REC recError = -1;
  34.  
  35. /*
  36.  *
  37.  * Header record for each created file.  Helps find deleted records
  38.  * within a file.
  39.  *
  40.  */
  41. struct FHEADER
  42.     {
  43.     friend class ACCESS;
  44. private:
  45.     REC recFirstActive;                    // First active record (Usually 0)
  46.     REC recFirstDeleted;                    // First deleted record
  47.     REC recLastDeleted;                    // Last deleted record
  48.     CCH cchSizeofRecord;                    //    Size of record when created
  49.     };
  50.  
  51. /*
  52.  *
  53.  * Record Headers
  54.  * Each record that is created & maintained using this system
  55.  * is a subclass of this.
  56.  * Using this approach.  We are able to control deleting and adding
  57.  * of records with minimum effort.  Derived classes have this without
  58.  * needing to code it.
  59.  *
  60.  */
  61. struct INF
  62.     {
  63.     friend class ACCESS;
  64. private:
  65.     REC recNextDeleted;                    // Next deleted record in the chain..
  66.     };
  67. typedef INF *PINF;
  68. STATIC CONST PINF pinfNil = 0;
  69.  
  70. /*
  71.  *
  72.  * Record manipulation.  Superclass for both INDEX/DATABASE file controls
  73.  * Handles deleting/saving or creating records
  74.  * In the future, this class will provide caching of records using a
  75.  * Least-Recently-Used Algorithm.  This is both Quick and Easy to implement
  76.  *
  77.  */
  78. class ACCESS
  79.     {
  80. public:
  81.     ACCESS(PINF pinf,CCH cchRecord,SZ szFileName,SZ szExtension,BOOL fCreateFile = fFalse);
  82.     ~ACCESS();
  83.     BOOL FFirst(VOID);
  84.     BOOL FSave(VOID);
  85.     BOOL FDelete(VOID);
  86.     BOOL FMark();
  87.     BOOL FGotoMark();
  88.     BOOL FGotoRec(REC rec);
  89.     REC RecCreate(VOID);
  90.     REC RecQuery(VOID);
  91.     REC RecMaxQuery(VOID);
  92.     PINF PinfQuery(VOID);
  93. protected:
  94.     BOOL FMakeFirstRec(REC rec);
  95. private:
  96.     BOOL FUpdateDatabase(PINF pinf,SZ sz,CCH cchNew,CCH cchOld);
  97.     BOOL FCreateFile(SZ sz);
  98.     SZ SzFullPathFromSzSz(SZ sz,SZ szExtension);
  99.     REC RecFromStmCch(FILE *stmInput,CCH cchInput);
  100.     FHEADER fhd;
  101.     REC recMax;
  102.     REC recCurrent;
  103.     FILE *stmFile;
  104.     CCH cch;
  105.     PINF pinfBase;
  106.     CHAR *rgchStorage;
  107.     REC recMarked;
  108.     STATIC SZ szDataPath;
  109.     };
  110.  
  111.  
  112. #endif    /* !defined(__ACCESS__) */
  113.